class Store {
  constructor(name = 'session') {
    this.name = name
  }

  set(key, value) {
    window[`${this.name}Storage`].setItem(key, value)
  }

  get(key, defaultValue = '') {
    return window[`${this.name}Storage`].getItem(key) ? window[`${this.name}Storage`].getItem(key) : defaultValue
  }

  has(key) {
    return window[`${this.name}Storage`].getItem(key) ? true : false
  }

  remove(key) {
    window[`${this.name}Storage`].getItem(key) && window[`${this.name}Storage`].removeItem(key)
  }

}

// 搞了一个工厂函数
export default (name = 'session') => new Store(name)